<?php

namespace sframe;

use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Controller\ControllerResolver as KernelControllerResolver;

class ControllerResolver extends KernelControllerResolver
{
	private $logger;

	public function __construct(LoggerInterface $logger = null)
	{
		$this->logger = $logger;
	}

	/**
	 * Returns a callable for the given controller.
	 *
	 * @param string $controller A Controller string
	 *
	 * @return callable A PHP callable
	 */
	protected function createController($controller)
	{
		if (false === strpos($controller, '::')) {
			return $this->instantiateController($controller);
		}

		list($class, $method) = explode('::', $controller, 2);

		try {
			return [$this->instantiateController($class), $method];
		}
		catch (\Throwable $e) {

			try {
				if ((new \ReflectionMethod($class, $method))->isStatic()) {
					return $class . '::' . $method;
				}
			}
			catch (\Throwable $t) {
				ExceptionHandler::process($e, APP_DEBUG)->send();
				exit;
			}
		}
	}
}
